package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.SupplierDao;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author :ttm
 * @description :
 */
@Service
public class SupplierServiceImpl implements SupplierService {

    @Autowired
    private SupplierDao supplierDao;

    @Override
    public Map<String, Object> list(Integer page, Integer rows, String supplierName) {
        List<Supplier> suppliers = supplierDao.list(supplierName);
        HashMap<String, Object> map = new HashMap<>();
        map.put("rows", suppliers);
        return map;
    }

    @Override
    public ServiceVO save(Supplier supplier) {

        return supplierDao.save(supplier);
    }

    @Override
    public ServiceVO delete(String ids) {
        String[] split = ids.split(",");
        for (String id : split) {
            supplierDao.delete(id);
        }
        return null;
    }

    @Override
    public List<Supplier> getComboboxList(String q) {
        return supplierDao.getSupplierListByNameLike(q);
    }


}
